using System;
using System.Collections.Generic;
using System.Text;
using Calc.Execution;

namespace Calc.Operations
{
	public class ModuloOperator : BinaryOperator
	{
		public override CalcResult Calc(ExecutionContext context)
		{
			if ( _leftSide == null )
				throw new ArgumentNullException("LeftSide", "LeftSide is null, so a calculation is not possible");

			if ( _rightSide == null )
				throw new ArgumentNullException("RightSide", "RightSide is null, so a calculation is not possible");

			double left = _leftSide.GetValue(context);
			double right = _rightSide.GetValue(context);

			_value = left % right;

			return new CalcResult(_value);
		}

		public override int Precidence
		{
			get { return 20; }
		}

		public override string Symbol
		{
			get { return "%"; }
		}

		public override string ToString()
		{
			string left = "";
			if ( _leftSide != null )
				left = _leftSide.ToString();

			string right = "";

			if ( _rightSide != null )
				right = _rightSide.ToString();

			return left + Symbol + right;
		}
	}
}
